package org.pps.gl.client.vue;

import org.pps.gl.client.Pps_gl;
import org.pps.gl.client.events.ConnectedEvent;
import org.pps.gl.client.events.ConnectedEventHandler;
import org.pps.gl.client.events.SignOutEvent;
import org.pps.gl.client.events.SignOutEventHandler;


import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.Image;
import com.google.gwt.user.client.ui.HasHorizontalAlignment;
import com.google.gwt.user.client.ui.VerticalPanel;
import com.google.gwt.user.client.ui.HasVerticalAlignment;

/**
 * Haut de page, logos et cadre de connexion
 * 
 */
public class Header extends Composite implements ConnectedEventHandler,
		SignOutEventHandler {

	private HorizontalPanel dockPanel;
	private HDR_Login login;
	VerticalPanel connected;
	HDR_Connect vheader;

	public Header() {

		dockPanel = new HorizontalPanel();
		initWidget(dockPanel);
		dockPanel.setSize("100%", "100%");
		dockPanel.setSpacing(10);
		HorizontalPanel images = new HorizontalPanel();
		Image image = new Image("images/logos/Polytech+2.gif");
		image.setStyleName("#logo_accueil");
		image.setAltText("logo-pplus");
		Image squareanim = new Image("images/squareanim.gif");
		squareanim.setStyleName("#logo_accueil");
		squareanim.setAltText("anim-pplus");
		images.add(image);
		images.setCellVerticalAlignment(image,
				HasVerticalAlignment.ALIGN_MIDDLE);
		images.add(squareanim);
		images.setCellVerticalAlignment(squareanim,
				HasVerticalAlignment.ALIGN_MIDDLE);
		dockPanel.add(images);
		dockPanel.setCellHorizontalAlignment(images,
				HasHorizontalAlignment.ALIGN_LEFT);
		login = new HDR_Login();
		dockPanel.add(login);
		dockPanel.setCellHorizontalAlignment(login,
				HasHorizontalAlignment.ALIGN_RIGHT);

		Pps_gl.getCm().addConnectedEventHandler(login);
	}

	public void onConnected(ConnectedEvent event) {
		vheader = new HDR_Connect(event);
		dockPanel.remove(login);
		dockPanel.add(vheader);
		dockPanel.setCellHorizontalAlignment(vheader,
				HasHorizontalAlignment.ALIGN_RIGHT);
	}

	/**
	 * Après déconnexion, on retire le header avec les informations et on remet
	 * le cadre pour se connecter
	 */
	public void onSignOut(SignOutEvent signOutEvent) {
		dockPanel.remove(vheader);
		dockPanel.add(login);
		dockPanel.setCellHorizontalAlignment(login,
				HasHorizontalAlignment.ALIGN_RIGHT);
	}

}
